import Enity from "./Enity.js"
import { hpPropImg } from "../image.js"
class HpProp extends Enity {
    type = 'prop'
    name = "加血道具"
    hp = 1
    img;//图片
    v;//移动速度
    time = 0;//存活时间
    //参数
    timer = null;//内置定时器
    movePlan = 1;
    constructor(x, y) {
        super(x, y, 8)
        this.img = {
            body: hpPropImg,
        }
        this.v = 0.5
    }
    draw(ctx) {
        ctx.drawImage(this.img.body, this.x - this.R, this.y - this.R, this.R * 2, this.R * 2)
    }
    behavior = function (context) {
        this.time++
        this.move(context)
        context = this.hit(context)
        return context
    }
    //撞击判断
    hit = function (context) {
        let player = context.NodeList[1]
        if (this.nodeDistance(player) <= this.R + player.R - 5) {
            if (player.hp && player.hp<=5) {//玩家最大hp5
                player.hp += this.hp
                this.OK = false
            }
        }
        return context
    }
    move() {
        if (this.hp <= 0) return
        this.y += this.v
        switch (this.movePlan) {
            case 1: {
                this.x -= this.v*1.5
                if (this.x <= 0) this.movePlan = 2
                break;
            }
            case 2: {
                this.x += this.v*1.5
                if (this.x >= 500) this.movePlan = 1
                break;
            }
        }

    }
    isOK(context) {
        if (this.y >= 600) {
            this.OK = false
        }
        return context
    }
}
export default HpProp